package com.ali.resource.CompoentPage;

import com.ali.resource.ShareTools.TeaopenapiClient;
import com.aliyun.ecs20140526.Client;
import com.aliyun.ecs20140526.models.DescribeInstancesRequest;
import com.aliyun.ecs20140526.models.DescribeInstancesResponse;
import com.aliyun.teaopenapi.models.Config;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class RedisComponent {


    @Autowired
    private TeaopenapiClient teaopenapiClient;


    public com.aliyun.r_kvstore20150101.Client  getRedisClient() throws Exception {
        // 获取teaopenapiClient
        Config openapiClient = teaopenapiClient.getClient();

        // 设置端点
        openapiClient.setEndpoint("r-kvstore.aliyuncs.com");

        // new redis客户端，并传入teaopenapiClient客户端
        com.aliyun.r_kvstore20150101.Client client = new com.aliyun.r_kvstore20150101.Client(openapiClient);
        return client;
    }


    public com.aliyun.r_kvstore20150101.models.DescribeInstancesRequest getRequest(){

        // 设置请求参数
        com.aliyun.r_kvstore20150101.models.DescribeInstancesRequest describeInstancesRequest = new com.aliyun.r_kvstore20150101.models.DescribeInstancesRequest();
        describeInstancesRequest.setRegionId("cn-shanghai");

        return describeInstancesRequest;
    }


    public com.aliyun.r_kvstore20150101.models.DescribeInstancesResponse getInstancesResource(com.aliyun.r_kvstore20150101.models.DescribeInstancesRequest request) throws Exception {

        // 发送请求
        com.aliyun.r_kvstore20150101.models.DescribeInstancesResponse dis = this.getRedisClient().describeInstancesWithOptions(request, teaopenapiClient.getRunTime());
        return dis;
    }

}
